<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    const isObject=(target)=>(typeof target==="object"||typeof target==="function")&&target!==null
    function deepClone(target,map=new Map()){
        if(map.get(target))return target
        if(isObject(target)){
            map.set(target,true)   
            const cloneTarget=Array.isArray(target)?[]:{}
            for(let prop in target){
                // if(target.hasOwnProperty(prop)){
                    cloneTarget[prop]=deepClone(target[prop],map)
                // }
            }
            return cloneTarget
        }else{
            return target
        }
    }
    const a = {val:2};
    a.target = a;
    let newA = deepClone(a);
</script>
</html>